package com.designoutput.ui.gallery
{
	import com.designoutput.icon.Next;
	import com.designoutput.icon.Previous;
	import com.designoutput.ui.controls.Literal;
	import com.designoutput.ui.controls.ToolButton;
	import com.designoutput.ui.newControls.ControlBase;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * The footer for the gallery. Contains the previous&next button and the page information.
	 */	
	public class GalleryFooter extends ControlBase
	{
		private var _parentGallery:GalleryGrid;

		private var _previousBtn:ToolButton;
		private var _nextBtn:ToolButton;
		private var _pageInfor:Literal;
		
		public function GalleryFooter(parentGallery:GalleryGrid)
		{
			_parentGallery = parentGallery;
		}
		
		override protected function initialize():void {
			_previousBtn = new ToolButton("Previous", new Previous(0, 0), 4, 4, 40, 38, false);
			_previousBtn.addEventListener(MouseEvent.MOUSE_DOWN, onPrevious);
			_previousBtn.buttonMode = true;
			_previousBtn.x = 10;
			_previousBtn.y = 10;
			addChild(_previousBtn);
			
			_pageInfor = new Literal("", false, 0xFFFFFF);
			_pageInfor.width = 100;
			_pageInfor.y = 20;
			addChild(_pageInfor);
			
			_nextBtn = new ToolButton("Next", new Next(0, 0), 4, 4, 40, 38, false);
			_nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, onNext);
			_nextBtn.buttonMode = true;
			_nextBtn.y = 10;
			addChild(_nextBtn);
		}
		
		override protected function updateDisplay():void {
			super.updateDisplay();
			
			graphics.clear();
			graphics.beginFill(0xD3D6DB,0.5);
			graphics.drawRect(0,0, _width, _height);
			graphics.endFill();
			
			_pageInfor.x = (_width - _pageInfor.width)/2;
			_previousBtn.x = _pageInfor.x - 80;
			_nextBtn.x = _pageInfor.x + 100;
		}
		
		public function showNextBtn(flag:Boolean):void{
			_nextBtn.visible = flag;
		}
		
		public function showPreviousBtn(flag:Boolean):void{
			_previousBtn.visible = flag;
		}
		
		public function showPageInfor(flag:Boolean):void{
			_pageInfor.visible = flag;
		}
		
		public function setPageInfor(txt:String):void{
			_pageInfor.text = txt;
		}
		
		private function onPrevious(evt:MouseEvent):void{
			_parentGallery.previousPage();
		}
		
		private function onNext(evt:MouseEvent):void{
			_parentGallery.nextPage();
		}
	}
}